package com.youlg.controller;

import com.youlg.pojo.Admin;
import com.youlg.service.Admin.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class AdminController {

    @Autowired
    @Qualifier("AdminServiceImpl")
    private AdminService adminService;

    @RequestMapping("/index")
    public String admin(){
        return "forward:/index.jsp";
    }

    @RequestMapping("/admin")
    public String admin(Admin admin, HttpSession session, Model model){
        Admin queryAdmin = adminService.queryAdmin(admin);

        if(queryAdmin != null){
            session.setAttribute("user_uuid",queryAdmin.getAdmin_uuid());
            return "forward:/book/allBook";
        }
        model.addAttribute("error","用户名或密码错误");
        return "forward:/index";
    }

    @RequestMapping("/Out")
    public String out(HttpSession session){

        session.removeAttribute("user_uuid");

        return "redirect:/index.jsp";
    }
}
